package io.github.harmonly.mapper;

import io.github.harmonly.entity.activity.Activity;
import io.github.harmonly.entity.activity.ActivityComment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityMapper {

    @Select("select * from activity where name like '%' #{keyword} '%'")
    List<Activity> getActivitiesByKeyWord(String keyword);

    @Select("select * from activity where aid = #{aid}")
    List<Activity> getActivitiesByAssociation(int aid);

    @Select("select * from activity")
    List<Activity> getActivities();

    @Select("select * from activity where cid = #{cid}")
    Activity getActivity(int cid);

    @Insert("insert into activity(aid, name, content, start, end, face, people, location, star) VALUES (#{aid}, #{name}, #{content}, #{start}, #{end}, #{face}, #{people}, #{location}, #{star})")
    int addActivity(Activity activity);

    @Delete("delete activity from activity where cid = #{cid}")
    int deleteActivity(int cid);

    @Update("update activity set aid = #{aid}, name = #{name}, content = #{content}, start = #{start}, end = #{end}, face = #{face}, people = #{people}, location = #{location}, star = #{star} where cid = #{cid}")
    int editActivity(Activity activity);

    @Select("select * from activity_comment")
    List<ActivityComment> getComments();

    @Select("select * from activity_comment where cid = #{cid}")
    List<ActivityComment> getCommentsByCid(int cid);

    @Select("select * from activity_comment where ccid = #{ccid}")
    ActivityComment getComment(int ccid);

    @Insert("insert into activity_comment(cid, uid, content, time) VALUES (#{cid}, #{uid}, #{content}, #{time})")
    int addComment(ActivityComment comment);

    @Delete("delete activity_comment from activity_comment where ccid = #{ccid}")
    int deleteComment(int ccid);

    @Update("update activity_comment set cid = #{cid}, uid = #{uid}, content = #{content}, time = #{time} where ccid = #{ccid}")
    int editComment(ActivityComment comment);
}
